package com.example.player.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.easefun.polyvsdk.sub.vlms.entity.PolyvVlmsCoursesInfo;
import com.example.player.PolyvImageLoader;
import com.example.player.R;
import java.util.List;



public class HotCourseGridViewAdapter extends BaseAdapter {
    private Context context;
    private List<PolyvVlmsCoursesInfo> lists;
    private LayoutInflater inflater;
    private ViewHolder viewHolder;

    private class ViewHolder{
        ImageView iv_demo;
        TextView tv_teac,tv_title,tv_learn,tv_money;
    }

    public HotCourseGridViewAdapter(Context context,List<PolyvVlmsCoursesInfo> lists){
        this.context = context;
        this.lists=lists;
        this.inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() { return lists.size(); }

    @Override
    public Object getItem(int position) { return lists.get(position); }

    @Override
    public long getItemId(int position) { return position; }

    @Override
    public View getView(int position,View convertView, ViewGroup parent) {
        if(convertView == null) {
            convertView = inflater.inflate(R.layout.polyv_gridview_hc_item,null);
            viewHolder = new ViewHolder();
            viewHolder.iv_demo=(ImageView) convertView.findViewById(R.id.iv_demo);
            viewHolder.tv_learn=(TextView) convertView.findViewById(R.id.tv_learn);
            viewHolder.tv_title=(TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.tv_teac=(TextView) convertView.findViewById(R.id.tv_teacher);
            viewHolder.tv_money=(TextView) convertView.findViewById(R.id.tv_money);
            convertView.setTag(viewHolder);
        }else{
            viewHolder=(ViewHolder)convertView.getTag();
        }
        PolyvVlmsCoursesInfo coursesDetail = lists.get(position);
        viewHolder.tv_title.setText(coursesDetail.getTitle());
        viewHolder.tv_teac.setText(coursesDetail.getTeacherName());
        viewHolder.tv_learn.setText((coursesDetail.getStudentNum())+"人在学");
        if (coursesDetail.getIsFree().equals(PolyvVlmsCoursesInfo.IS_FREE_YES)) {
            viewHolder.tv_money.setText("免费");
            viewHolder.tv_money.setTextColor(context.getResources().getColor(android.R.color.holo_green_light));
        }else{
            viewHolder.tv_money.setText("￥" + coursesDetail.getPrice());
            viewHolder.tv_money.setTextColor(context.getResources().getColor(android.R.color.holo_red_light));
        }
//        viewHolder.tv_money.setTextColor(context.getResources().getColor(R.color.black));
        PolyvImageLoader.getInstance().loadImageWithCache(context, coursesDetail.getCoverImage(), viewHolder.iv_demo, R.drawable.polyv_demo);
        return convertView;
    }
}
